home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3MCp.sea Folder / Made by Marksman / Sources / mm / mmCommonMM_Demo.cp < prev    next >
Encoding:
Text File  |  1994-01-16  |  69.2 KB  |  2,189 lines  |  [TEXT/MMCC]

  1. /*  mmCommonMM_Demo                         Common */
  2. /*  Copyright Â© 1994 George R. Cossey */
  3.  
  4. /*
  5.     Name:  mmCommonMM_Demo.c
  6.     Function:  Common for the Marksman™ specific code.
  7.     History: 1/16/94 Original by George Cossey
  8.  
  9. */
  10.  
  11.  
  12. #include "mmCommonMM_Demo.h"            /* Common */
  13. #include "CommonMM_Demo.h"                /* Common */
  14.  
  15. #include <Sound.h>
  16.  
  17. /* ======================================================= */
  18.  
  19. CApplication    *gApplication;                    /* The application itself */
  20. CMenus            *gMenus;                        /* Menu handler */
  21. CPreferences    *gPreferences;                    /* Preferences handler */
  22. CFiles            *gFiles;                        /* Files handler */
  23. CPrinting        *gPrinting;                        /* Printing handler */
  24.  
  25. UserEventHRec    UserEventList;                    /* User Event record list start */
  26. EventRecord        myEvent;                        /* Event record for all events */
  27. Boolean            WNE;                            /* WaitNextEvent trap is available */
  28. short            SleepValue;                        /* Sleep value for Wait on events */
  29. Boolean            doneFlag;                        /* Exit program flag */
  30. TEHandle        theInput;                        /* Used in text edit selections */
  31. RgnHandle        cursorRgn;                        /* Cursor region for WaitNextEvent */
  32. short            ReplyMode;                        /* Reply mode for AppleEvents */
  33.  
  34. Rect            tempRect;                        /* Temporary rect, not for long term use */
  35. Str255            sTemp;                            /* Temporary string, not for long term use */
  36. short            tempChar;                        /* Temporary use character */
  37. long            LTemp;                            /* Temporary use long variable */
  38. short            DType;                            /* Temporary use Type of dialog item */
  39. Handle            DItem;                            /* Temporary use Handle to the dialog item */
  40. ControlHandle    CItem;                            /* Temporary use Control handle */
  41.  
  42. WindowLocRec    theWindowLocRec;
  43.  
  44. Boolean            Doing_MovableModal;                /* For Movable Modal dialogs */
  45. Boolean            HoldOffUserEvents;                /* Flag for holding off UserEvents */
  46. Boolean            InTheForeground;                /* Flag for running in MultiFinder foreground */
  47.  
  48. HasRec            Has;                            /* Gestalt check results */
  49.  
  50. RGBColor        Black_ForeColor,White_BackColor;/* Standard colors */
  51.  
  52. MenuHandle    Menu_Apple;                    /* Menu handle,  */
  53. MenuHandle    Menu_File;                    /* Menu handle, File */
  54. MenuHandle    Menu_Edit;                    /* Menu handle, Edit */
  55. MenuHandle    Menu_Windows;                    /* Menu handle, Windows */
  56.  
  57.  
  58. CmmAlert                *gCurrentAlert;            /* The current Alert object */
  59. CAMy_Alert        *gMy_Alert;        /* The Alert object */
  60. CmmModalDialog            *gCurrentModalDialog;    /* The current Modal Dialog object */
  61. CDMy_Modal        *gMy_Modal;        /* The Modal Dialog object */
  62. CMDMy_Movable_Moda        *gMy_Movable_Moda;        /* The Modeless Dialog object */
  63. CMDMy_Modeless        *gMy_Modeless;        /* The Modeless Dialog object */
  64. CMDAbout_Demo        *gAbout_Demo;        /* The Modeless Dialog object */
  65. CWMy_basic_window        *gMy_basic_window;        /* The Window object */
  66. CWFloating_window        *gFloating_window;        /* The Window object */
  67.  
  68.  
  69. #define            LowestWindowIndex            0
  70. #define            HighestWindowIndex            10
  71. WindowPtr        TopMostWindows[12];
  72. WindowPtr        BottomMostWindows[12];
  73.  
  74. #define            lmWindowList                0x000009D6
  75.  
  76. /* Variables used by Select Volume */
  77. short            Last_vRefNum;
  78. long            Last_parID;
  79. Str255            Last_Name;
  80.  
  81. static void    VerifyWindowLayers(void);
  82.  
  83. static pascal Boolean mySelectCustomFileFilter(CInfoPBPtr pb,Ptr myDataPtr);
  84.  
  85. static pascal short mySelectDlgFilter(short item,DialogPtr theDialog,Ptr myDataPtr);
  86.  
  87. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  88.     ControlHandle *theCItem);
  89.  
  90. /* ======================================================= */
  91. /* ======================================================= */
  92.  
  93. /* Routine: VerifyWindowLayers */
  94. /* Purpose: Verify all windows are at the proper layer */
  95.  
  96. static void VerifyWindowLayers()
  97. {
  98. short        Index,theLayer;
  99. WindowPeek    theWindowPeek;
  100. long         *theWindowListPtr,theRefCon;
  101. WindowPtr    theWindowPtr,theOutOfOrderWindowPtr;
  102. Boolean        Out_Of_Place;
  103.  
  104.  
  105. Out_Of_Place = true;
  106. while (Out_Of_Place)
  107.     {
  108.     Mk_ClearLayers();                                /* Clear all arrays, we will refill them */
  109.     theOutOfOrderWindowPtr = nil;
  110.     Out_Of_Place = false;
  111.  
  112.     Index = HighestWindowIndex + 1;
  113.     theWindowListPtr = (long *)lmWindowList;        /* Get the window list start */
  114.     theWindowPeek = (WindowPeek)*theWindowListPtr;    /* Get the window list start */
  115.     while ((theWindowPeek != nil) && (!Out_Of_Place))
  116.         {
  117.         if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  118.             {
  119.             theWindowPtr = (WindowPtr)theWindowPeek;/* Get the window pointer */
  120.  
  121.             theRefCon = GetWRefCon(theWindowPtr);
  122.             theRefCon = theRefCon & 0xFF000000;        /* Mask off, to get the layer */
  123.             theLayer = theRefCon >> 24;                /* Move into lower byte */
  124.             if (theLayer < LowestWindowIndex)        /* Pin at 0 */
  125.                 theLayer = LowestWindowIndex;
  126.             if (theLayer > HighestWindowIndex)        /* Pin at top */
  127.                 theLayer = HighestWindowIndex;
  128.             if (theLayer > Index)
  129.                 {
  130.                 Index = theLayer;
  131.                 Out_Of_Place = true;
  132.                 if (theOutOfOrderWindowPtr != nil)
  133.                     SendBehind(theOutOfOrderWindowPtr,theWindowPtr);
  134.                 }
  135.             else if (theLayer < Index)
  136.                 {
  137.                 Index = theLayer;
  138.                 TopMostWindows[theLayer] = theWindowPtr;
  139.                 BottomMostWindows[theLayer]  = theWindowPtr;
  140.                 }
  141.             else
  142.                 BottomMostWindows[theLayer]  = theWindowPtr;
  143.             theOutOfOrderWindowPtr = theWindowPtr;
  144.             }
  145.         theWindowPeek = theWindowPeek->nextWindow;/* Get the next window */
  146.         }
  147.     }
  148.  
  149. }
  150.  
  151. /* ======================================================= */
  152.  
  153. /* Routine: Mk_BehindWindow */
  154. /* Purpose: Get which window to place us behind */
  155.  
  156. WindowPtr Mk_BehindWindow(short theLayer)
  157. {
  158. short        LayerIndex;
  159. WindowPtr    ReturnWindowPtr;
  160.  
  161.  
  162. ReturnWindowPtr = (WindowPtr)-1;                    /* Default to In front of everyone */
  163.  
  164. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  165.  
  166. LayerIndex = HighestWindowIndex;
  167. while ((LayerIndex > theLayer) && (LayerIndex >= LowestWindowIndex))
  168.     {
  169.     if (BottomMostWindows[LayerIndex] != nil)
  170.         ReturnWindowPtr = BottomMostWindows[LayerIndex];
  171.     LayerIndex = LayerIndex - 1;
  172.     }
  173.  
  174. return(ReturnWindowPtr);
  175. }
  176.  
  177. /* ======================================================= */
  178.  
  179. /* Routine: Mk_RegisterWindow */
  180. /* Purpose: Place layer in RefCon and verify layers */
  181.  
  182. void Mk_RegisterWindow(WindowPtr theWindowPtr,short theLayer)
  183. {
  184. long    theRefCon;
  185. long    theLLayer;
  186.  
  187.  
  188. theRefCon = GetWRefCon(theWindowPtr);                /* Get the window refcon */
  189. theRefCon = theRefCon & 0x00FFFFFF;                    /* Mask off, in case something else is there */
  190. theLLayer = theLayer;                                /* Get the window layer */
  191. theLLayer = theLLayer << 24;                        /* Move into upper byte */
  192. theRefCon = theRefCon | theLLayer;                    /* Mask layer into refcon */
  193. SetWRefCon(theWindowPtr, theRefCon);                /* Set the new refcon */
  194.  
  195. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  196. }
  197.  
  198. /* ======================================================= */
  199.  
  200. /* Routine: Mk_ClearLayers */
  201. /* Purpose: Init our arrays for layered windows */
  202.  
  203. void Mk_ClearLayers()
  204. {
  205. short    Index;
  206.  
  207.  
  208. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  209.     {
  210.     TopMostWindows[Index] = nil;
  211.     BottomMostWindows[Index] = nil;
  212.     }
  213. }
  214.  
  215. /* ======================================================= */
  216.  
  217. /* Routine: Mk_HiliteWindow */
  218. /* Purpose: Hilite our layered window */
  219.  
  220. void Mk_HiliteWindow(WindowPtr theWindowPtr)
  221. {
  222. WindowPeek    theWindowPeek;
  223. long         *theWindowListPtr;
  224. WindowPtr    WasHilighted,CkHilighted,BehindWindow;
  225. long        theRefCon;
  226. short        theLayer,theWasLayer;
  227.  
  228.  
  229. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  230.  
  231. theRefCon = GetWRefCon(theWindowPtr);
  232. theRefCon = 0xFF000000 & theRefCon;                    /* Mask for top byte */
  233. theLayer = theRefCon >> 24;                            /* Move into lower byte */
  234. if (theLayer < LowestWindowIndex)                    /* Pin at 0 */
  235.     theLayer = LowestWindowIndex;
  236. if (theLayer > HighestWindowIndex)                    /* Pin at top */
  237.     theLayer = HighestWindowIndex;
  238.  
  239. theWindowListPtr = (long *)lmWindowList;            /* Get the window list start */
  240. theWindowPeek = (WindowPeek)*theWindowListPtr;        /* Get the window list start */
  241. WasHilighted = nil;
  242. while (theWindowPeek != nil)
  243.     {
  244.     if ((theWindowPeek->visible) && (theWindowPeek->windowKind == userKind))
  245.         {
  246.         if (theWindowPeek->hilited)
  247.             {
  248.             CkHilighted = (WindowPtr)theWindowPeek;
  249.             theRefCon = GetWRefCon(CkHilighted);
  250.             theRefCon = 0xFF000000 & theRefCon;        /* Mask for top byte */
  251.             theWasLayer = theRefCon >> 24;            /* Move into lower byte */
  252.             if (theWasLayer == theLayer)
  253.                 WasHilighted = CkHilighted;
  254.             }
  255.         }
  256.     theWindowPeek = theWindowPeek->nextWindow;
  257.     }
  258.  
  259. if (theWindowPtr != WasHilighted)
  260.     {
  261.     if (WasHilighted != nil)
  262.         {
  263.         theRefCon = GetWRefCon(WasHilighted);
  264.         theRefCon = 0xFF000000 & theRefCon;            /* Mask for top byte */
  265.         theWasLayer = theRefCon >> 24;                /* Move into lower byte */
  266.         if (theWasLayer < LowestWindowIndex)        /* Pin at 0 */
  267.             theWasLayer = LowestWindowIndex;
  268.         if (theWasLayer > HighestWindowIndex)        /* Pin at top */
  269.             theWasLayer = HighestWindowIndex;
  270.         if (theWasLayer == theLayer)
  271.             {
  272.             HiliteWindow(WasHilighted, false);
  273.             myEvent.message = (long)WasHilighted;
  274.             myEvent.modifiers = 0;
  275.             gApplication->DoActivate(&myEvent);        /* Deactivate, do links */
  276.             }
  277.         }
  278.  
  279.     HiliteWindow(theWindowPtr, true);
  280.     myEvent.message = (long)theWindowPtr;
  281.     myEvent.modifiers = 1;
  282.     gApplication->DoActivate(&myEvent);                /* Activate, do links */
  283.  
  284.     BehindWindow = Mk_BehindWindow(theLayer);        /* Move to correct layer on the screen */
  285.     if ((long)BehindWindow == -1L)
  286.         BringToFront(theWindowPtr);
  287.     else
  288.         SendBehind(theWindowPtr, BehindWindow);
  289.  
  290.     TopMostWindows[theLayer] = theWindowPtr;
  291.     }
  292.  
  293. }
  294.  
  295. /* ======================================================= */
  296.  
  297. /* Routine: Mk_DragWindow */
  298. /* Purpose: Drag our layered window */
  299.  
  300. void Mk_DragWindow(WindowPtr theWindowPtr,Point where, Rect bounds)
  301. {
  302. GrafPtr            savePort;
  303. CGrafPtr        WMgrPort;
  304. RgnHandle        hRegion,dragRgn;
  305. WindowPeek        theWindowPeek;
  306. long            result;
  307. short            Horz,Vert;
  308. CWindowPtr        theCWindowPtr;
  309. Rect            portBounds;
  310. PixMapHandle    thePixMapHandle;
  311.  
  312.  
  313. if (WaitMouseUp())
  314.     {
  315.     theWindowPeek = (WindowPeek)theWindowPtr;
  316.     theCWindowPtr = (CWindowPtr)theWindowPtr;
  317.  
  318.     GetPort(&savePort);
  319.     if (Has.ColorQD)
  320.         GetCWMgrPort(&WMgrPort);
  321.     else
  322.         GetWMgrPort((GrafPtr *)&WMgrPort);
  323.     SetPort((GrafPtr)WMgrPort);
  324.     hRegion = GetGrayRgn();
  325.     SetClip(hRegion);
  326.  
  327.     ClipAbove(theWindowPeek);
  328.  
  329.     dragRgn = NewRgn();
  330.     CopyRgn(theWindowPeek->strucRgn, dragRgn);
  331.  
  332.     result = DragGrayRgn(dragRgn, where, &bounds, &bounds, 0, nil);
  333.     Horz = result;
  334.     Vert = result >> 16;
  335.  
  336.     if (Vert != 0x8000)
  337.         {
  338.         if ((theCWindowPtr->portVersion & 0xC000) != 0)
  339.             {
  340.             thePixMapHandle = theCWindowPtr->portPixMap;
  341.             portBounds = (*thePixMapHandle)->bounds;
  342.             }
  343.         else
  344.             portBounds = theWindowPtr->portBits.bounds;
  345.  
  346.         Horz = Horz + (theWindowPtr->portRect.left - portBounds.left);
  347.         Vert = Vert + (theWindowPtr->portRect.top - portBounds.top);
  348.  
  349.         MoveWindow(theWindowPtr, Horz, Vert, false);
  350.         }
  351.  
  352.     DisposeRgn(dragRgn);
  353.     SetPort(savePort);
  354.     }
  355.  
  356. }
  357.  
  358. /* ======================================================= */
  359.  
  360. /* Routine: Mk_Is_FrontWindow */
  361. /* Purpose: Get the front window */
  362.  
  363. Boolean Mk_Is_FrontWindow(WindowPtr theWindowPtr)
  364. {
  365. Boolean    IsFront;
  366. short    Index;
  367.  
  368.  
  369. IsFront = false;
  370. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  371.     {
  372.     if (TopMostWindows[Index] == theWindowPtr)
  373.         IsFront = true;
  374.     }
  375.  
  376. return(IsFront);
  377. }
  378.  
  379. /* ======================================================= */
  380.  
  381. /* Routine: Mk_CloseLayeredWindow */
  382. /* Purpose: Close a layered window */
  383.  
  384. void Mk_CloseLayeredWindow(WindowPtr theWindowPtr)
  385. {
  386. short    Index;
  387.  
  388.  
  389. for (Index = LowestWindowIndex; Index <= HighestWindowIndex; Index++)
  390.     {
  391.     if (TopMostWindows[Index] == theWindowPtr)
  392.         TopMostWindows[Index] = nil;
  393.     if (BottomMostWindows[Index] == theWindowPtr)
  394.         BottomMostWindows[Index] = nil;
  395.     }
  396. VerifyWindowLayers();                                /* Make sure our tables are up to date */
  397. }
  398.  
  399. /* ======================================================= */
  400.  
  401.  
  402. /* Routine: Init */
  403. /* Purpose: Set the default preferences */
  404.  
  405. void CmmPreferences::Init(void)
  406. {
  407. }
  408.  
  409. /* ======================================================= */
  410.  
  411. /* Routine: GetPrefParams */
  412. /* Purpose: Get the preferences Parameters */
  413.  
  414. void CmmPreferences::GetPrefParams(OSType *PrefCreator,OSType *PrefType,Str255 *thePrefsFilename,
  415.     long *PrefsRecSize,short *thePrefsFormatRevision)
  416. {
  417.  
  418. *PrefCreator = PrefsCreator;
  419. *PrefType = PrefsType;
  420. PStrCopy((Str255 *)PrefsFileName,thePrefsFilename);
  421. *PrefsRecSize = sizeof(PrefsRec);
  422. *thePrefsFormatRevision = PrefsFormatRevision;
  423. }
  424.  
  425. /* ======================================================= */
  426.  
  427. /* Routine: ReadPrefsPrivate */
  428. /* Purpose: Read the prefs ourselves */
  429.  
  430. void CmmPreferences::ReadPrefsPrivate(short PrefsRefNum)
  431. {
  432. }
  433.  
  434. /* ======================================================= */
  435.  
  436. /* Routine: UGetPreferences */
  437. /* Purpose: Get the preferences from the Prefs record already read in */
  438.  
  439. void CmmPreferences::UGetPreferences(Handle thePrefsH)
  440. {
  441. PrefsHRec thePrefs;
  442.  
  443.  
  444. thePrefs = (PrefsHRec)thePrefsH;
  445. theWindowLocRec = (*thePrefs)->theWindowLocRec;    /* Get the window location data */
  446. /* Use the form:   xxxx = (*thePrefs)->xxxx;    */
  447. }
  448.  
  449. /* ======================================================= */
  450.  
  451. /* Routine: USetPreferences */
  452. /* Purpose: Set new preferences, to be written out to the file */
  453.  
  454. void CmmPreferences::USetPreferences(Handle thePrefsH)
  455. {
  456. PrefsHRec thePrefs;
  457.  
  458.  
  459. thePrefs = (PrefsHRec)thePrefsH;
  460. (*thePrefs)->FormatRevision = PrefsFormatRevision;    /* Version number */
  461. (*thePrefs)->theWindowLocRec = theWindowLocRec;        /* Save the window location data */
  462. /* Use the form:   (*thePrefs)->xxxx = xxxx;    */
  463. }
  464.  
  465. /* ======================================================= */
  466.  
  467. /* Routine: GetPreferences */
  468. /* Purpose: Get the preferences */
  469.  
  470. void CmmPreferences::GetPreferences()
  471. {
  472. short        foundVRefNum,PrefsRefNum,FormatRevision,thePrefsFormatRevision;
  473. long        result,foundDirID,DataSize,count,PrefsRecSize;
  474. OSErr        theError;
  475. Boolean        GotPreferences,HasFindFolder;
  476. Str255        thePrefsFilename;
  477. Handle        PrefsHandle;
  478. FSSpec        PrefsFSSpec;
  479. OSType        PrefCreator,PrefType;
  480. SysEnvRec    theEnv;
  481.  
  482.  
  483. /* Get parameters to use */
  484. this->GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  485.  
  486. GotPreferences = false;                                /* No prefs yet */
  487. HasFindFolder = false;                                /* No FindFolder routine avail yet */
  488. PrefsRefNum = 0;                                    /* No prefs file yet */
  489.  
  490. if (Has.Gestalt)                                    /* Must have Gestalt */
  491.     {
  492.     theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  493.     if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))
  494.         HasFindFolder = true;
  495.  
  496.     if (HasFindFolder)                                /* Must have FindFolder */
  497.         {
  498.         theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);/* Get preference folder */
  499.         if (theError == 0)
  500.             {
  501.             theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  502.             if (theError == fnfErr)                    /* File not found */
  503.                 theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  504.             theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  505.             }
  506.         }
  507.     else
  508.         {
  509.         theError = SysEnvirons(1,&theEnv);            /* Get volume environs */
  510.         theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  511.         if (theError == fnfErr)                        /* File not found */
  512.             {
  513.             theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  514.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  515.             }
  516.         }
  517.  
  518.     if (theError == 0)
  519.         {
  520.         theError = GetEOF(PrefsRefNum,&DataSize);    /* See if data in the file */
  521.         if (DataSize > 0)                            /* Must have data in the file to go on */
  522.             {
  523.             count = 2;                                /* Revision number size */
  524.             theError = FSRead(PrefsRefNum,&count,&FormatRevision);/* Get revision number */
  525.             theError = SetFPos(PrefsRefNum,fsFromStart,0);/* Beginning again */
  526.  
  527.             if ((FormatRevision == thePrefsFormatRevision) && (PrefsRecSize > 0))/* Only do if up to date revision */
  528.                 {
  529.                 PrefsHandle = NewHandleClear(PrefsRecSize);/* Get space for the prefs */
  530.                 if (PrefsHandle != nil)                /* Make sure we got our little tiny handle */
  531.                     {
  532.                     HLock(PrefsHandle);                /* Lock this for safety */
  533.                     count = PrefsRecSize;            /* See how much data to read */
  534.                     theError = FSRead(PrefsRefNum,&count,*PrefsHandle);/* Read it on in */
  535.                     if (theError == 0)
  536.                         this->UGetPreferences(PrefsHandle);/* Let the user get the prefs */
  537.  
  538.                     GotPreferences = true;            /* Got our preferences */
  539.                     HUnlock(PrefsHandle);            /* OK to unlock now */
  540.                     DisposeHandle(PrefsHandle);        /* All done with this record  */
  541.                     }
  542.                 }
  543.             else
  544.                 this->ReadPrefsPrivate(PrefsRefNum);    /* Let the user read the prefs himself */
  545.             }
  546.         if (PrefsRefNum != 0)                        /* Done with the file , close it */
  547.             theError = FSClose(PrefsRefNum);
  548.         }
  549.     }
  550.  
  551. if (!GotPreferences )                                /* If we did not get prefs , use default values */
  552.     this->SetPreferences();                            /* Set the default values */
  553.  
  554. }
  555.  
  556. /* ======================================================= */
  557.  
  558. /* Routine: SetPreferences */
  559. /* Purpose: Set new preferences */
  560.  
  561. void CmmPreferences::SetPreferences()
  562. {
  563. Str255        thePrefsFilename;
  564. OSErr        theError;
  565. long        result,foundDirID,count,PrefsRecSize;
  566. short        foundVRefNum,PrefsRefNum,thePrefsFormatRevision;
  567. Handle        PrefsHandle;
  568. Boolean        HasFindFolder;
  569. FSSpec        PrefsFSSpec;
  570. OSType        PrefCreator,PrefType;
  571. SysEnvRec    theEnv;
  572.  
  573.  
  574. /* Get parameters to use */
  575. this->GetPrefParams(&PrefCreator,&PrefType,&thePrefsFilename,&PrefsRecSize,&thePrefsFormatRevision);
  576. PrefsRefNum = 0;
  577.  
  578. PrefsHandle = NewHandleClear(PrefsRecSize);            /* Allocate the prefs space holder */
  579.  
  580. if (PrefsHandle != nil)
  581.     {
  582.     HLock(PrefsHandle);                                /* Lock for safety */
  583.  
  584.     this->USetPreferences(PrefsHandle);                /* Let the user set the other pref values */
  585.  
  586.     HasFindFolder = false;
  587.     if (Has.Gestalt)                                /* Must have Gestalt */
  588.         {
  589.         theError = Gestalt(gestaltFindFolderAttr,&result);/* Need FindFolder */
  590.         if ((theError == 0) && ((result & (0x00000001 << gestaltFindFolderPresent)) != 0))/* See if FindFolder */
  591.             HasFindFolder = true;
  592.  
  593.         if (HasFindFolder )                            /* Must have FindFolder */
  594.             {
  595.             theError = FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,&foundVRefNum,&foundDirID);
  596.             if (theError == 0)
  597.                 {
  598.                 theError = FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,&PrefsFSSpec);
  599.                 if (theError == fnfErr)                /* File not found */
  600.                     theError = FSpCreate(&PrefsFSSpec,PrefCreator,PrefType,0);/* Create the file */
  601.                 theError = FSpOpenDF(&PrefsFSSpec,fsRdWrPerm,&PrefsRefNum);/* Open the file */
  602.                 }
  603.             }
  604.         else
  605.             {
  606.             theError = SysEnvirons(1,&theEnv);        /* Get volume environs */
  607.             theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  608.             if (theError == fnfErr)                    /* File not found */
  609.                 {
  610.                 theError = Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);/* Create the file */
  611.                 theError = FSOpen(thePrefsFilename,theEnv.sysVRefNum,&PrefsRefNum);/* Open the file */
  612.                 }
  613.             }
  614.  
  615.         if (theError == 0)
  616.             {
  617.             count = PrefsRecSize;
  618.             theError = FSWrite(PrefsRefNum,&count,*PrefsHandle);/* Write new prefs */
  619.             theError = SetEOF(PrefsRefNum,count);    /* Reset EOF */
  620.  
  621.             if (PrefsRefNum != 0)
  622.                 theError = FSClose(PrefsRefNum);    /* Close file */
  623.  
  624.             HUnlock(PrefsHandle);
  625.             DisposeHandle(PrefsHandle);                /* Done with Prefs handle */
  626.             }
  627.         }
  628.     }
  629.  
  630. }
  631.  
  632.  
  633. /* ======================================================= */
  634.  
  635. void PositionWindow(WindowPtr theWindow,Point  WantLocation,Point DefaultPosition)
  636. {
  637. Boolean        FitsOK;
  638. Rect        WindowRect;
  639. GrafPtr        theDesktopPort;
  640. RgnHandle    theRgn,the2Rgn;
  641.  
  642.  
  643. FitsOK = false;                                        /*Init to not on current screen(s) */
  644. WindowRect = theWindow->portRect;                    /* Save the rect to get the size */
  645. OffsetRect(&WindowRect,-WindowRect.left,-WindowRect.top);    /* Offset to 0,0 */
  646. OffsetRect(&WindowRect,WantLocation.h,WantLocation.v);        /* Offset to wanted location */
  647.  
  648. GetWMgrPort(&theDesktopPort);                        /* Get the screen */
  649.  
  650. theRgn = NewRgn();                                    /* Make temp regions */
  651. the2Rgn = NewRgn();
  652. RectRgn(theRgn,&WindowRect);                        /* First region to our window rectangle on the screen */
  653. SectRgn(theRgn,theDesktopPort->visRgn,the2Rgn);        /* Do the intersection with the screen and window */
  654. if (EqualRgn(theRgn,the2Rgn))                        /* If all of window in the screen area then ... */
  655.     FitsOK = true;                                    /* ...all of the window is on the screen area */
  656.  
  657. DisposeRgn(theRgn);                                    /* Dispose of temp regions */
  658. DisposeRgn(the2Rgn);
  659. if ((FitsOK) && ((WantLocation.h != 0) || (WantLocation.v != 0)))    /* If all of window in the screen area then ... */
  660.     MoveWindow(theWindow,WantLocation.h,WantLocation.v,false);    /* Move to saved location */
  661. else
  662.     MoveWindow(theWindow,DefaultPosition.h,DefaultPosition.v,false); /* Move to original location */
  663. }
  664.  
  665. /* ======================================================= */
  666.  
  667. /* Routine: PStrCopy */
  668. /* Purpose: Copy Pascal strings */
  669.  
  670. void PStrCopy(Str255 *SourceString, Str255 *DestString)/* Copy Pascal strings */
  671. {
  672.  
  673.  
  674. *DestString[0] = *SourceString[0];                    /* Get the string size */
  675. if (*DestString[0] != 0)                            /* Do if there is anything in the string */
  676.     BlockMove(SourceString,DestString,*DestString[0]+1);
  677. }
  678.  
  679. /* ======================================================= */
  680.  
  681. /* Routine: PStrCat */
  682. /* Purpose: Concat Pascal strings */
  683.  
  684. void PStrCat(Str255 *SourceString, Str255 *DestString)/* Concat Pascal strings */
  685. {
  686. short    OldDestLength,NewDestLength,SizeFromSource;
  687.  
  688.  
  689. OldDestLength = *DestString[0];                        /* Get the string old length */
  690. SizeFromSource = *SourceString[0];                    /* Get the source length */
  691. NewDestLength = OldDestLength + SizeFromSource;        /* Get the string new length */
  692. if (NewDestLength > 255)                            /* Compare to length of the final string */
  693.     {
  694.     NewDestLength = 255;                            /* The string final length */
  695.     SizeFromSource = 255 - OldDestLength;            /* The string final length */
  696.     }
  697.  
  698. *DestString[0] = NewDestLength;                        /* Set the string length */
  699. if (SizeFromSource > 0)                                /* Do if there is anything in the string */
  700.     BlockMove((Ptr)((long)SourceString + 1L),(Ptr)((long)DestString+OldDestLength+1L),SizeFromSource);
  701. }
  702.  
  703. /* ======================================================= */
  704.  
  705. /* Routine: PStrCmp */
  706. /* Purpose: Compare Pascal strings for exact match, case sensitive */
  707.  
  708. Boolean PStrCmp(StringPtr Source1String,StringPtr Source2String)/* Compare Pascal strings */
  709. {
  710. short        theLength,Index;
  711. Boolean        theSame;
  712.  
  713.  
  714. theSame = false;                                    /* Init to different */
  715. theLength = *Source1String++;                        /* Get length of one string */
  716. if (theLength == *Source2String++)                    /* Compare to length of other string, easy and quick check */
  717.     {
  718.     theSame = true;                                    /* Init to same, now we will check each character */
  719.     for (Index=1; Index <= theLength; Index++)        /* Compare to length of other string, easy and quick check */
  720.         {
  721.         if (*Source1String++ != *Source2String++)    /* See if this character is the same */
  722.             theSame = false;                        /* Different */
  723.         }
  724.     }
  725.  
  726. return(theSame);
  727. }
  728.  
  729. /* ======================================================= */
  730.  
  731. /* Routine: CheckTrapAvailable */
  732. /* Purpose: See if trap is available, non-available traps all have a unique address */
  733.  
  734. Boolean CheckTrapAvailable (short trapNumber,short tType)/* See if a trap is available */
  735. {
  736. #define UnimplementedTrapNumber     0xA89F            /* Unimplemented trap number */
  737. Boolean    theResult;
  738.  
  739.  
  740. /* Check the two traps */
  741. theResult = (NGetTrapAddress(trapNumber, tType) != GetTrapAddress(UnimplementedTrapNumber));
  742.  
  743. return(theResult);
  744. }
  745.  
  746. /* ======================================================= */
  747.  
  748. /* Routine: GetUserEvent */
  749. /* Purpose: See if any user events are available */
  750.  
  751. void GetUserEvent(UserEventPRec TheUserEvent)
  752. UserEventHRec    NextUserEvent;                        /* The next user event */
  753.  
  754.  
  755. TheUserEvent->ID = UserEvent_None;                    /* Set ID to no events are available */
  756. if (UserEventList != NIL)                            /* Get first entry in the list */
  757.     {
  758.     HLock((Handle)UserEventList);                    /* Lock for safety */
  759.     TheUserEvent->ID = (*UserEventList)->ID;        /* The event ID */
  760.     TheUserEvent->ID2 = (*UserEventList)->ID2;        /* The optional ID */
  761.     TheUserEvent->Data1 = (*UserEventList)->Data1;    /* The optional data */
  762.     TheUserEvent->Data2 = (*UserEventList)->Data2;    /* The optional data */
  763.     TheUserEvent->theHandle = (*UserEventList)->theHandle;/* The optional handle */
  764.     NextUserEvent = (*UserEventList)->Next;            /* The next list */
  765.  
  766.     DisposHandle((Handle)UserEventList);            /* Remove this list item */
  767.     UserEventList = NextUserEvent;                    /* Make the next item the new first item */
  768.     }
  769. }
  770.  
  771. /* ======================================================= */
  772.  
  773. /* Routine: Add_UserEvent */
  774. /* Purpose: Add a user event */
  775.  
  776. void Add_UserEvent(short ID1,short  ID2,long Data1,long Data2,Handle  theHandle)
  777. UserEventHRec    NewUserEvent;                        /* The new user event */
  778. UserEventHRec    theUserEvent;                        /* The user event */
  779.  
  780.  
  781. NewUserEvent = (UserEventHRec)NewHandle(sizeof(UserEventRec));/* Allocate a record */
  782. if (NewUserEvent != NIL)                            /* Only do if we got the new record */
  783.     {
  784.     HLock((Handle)NewUserEvent);                    /* Lock for safety */
  785.     (*NewUserEvent)->ID = ID1;                        /* The event ID */
  786.     (*NewUserEvent)->ID2 = ID2;                        /* The optional ID */
  787.     (*NewUserEvent)->Data1 = Data1;                    /* The optional data */
  788.     (*NewUserEvent)->Data2 = Data2;                    /* The optional data */
  789.     (*NewUserEvent)->theHandle = theHandle;            /* The optional handle */
  790.     (*NewUserEvent)->Next = NIL;                    /* No next item after this one */
  791.  
  792.     if (UserEventList == NIL)                        /* See if anyone is in the list yet */
  793.         UserEventList = NewUserEvent;                /* Make this one the first in the list */
  794.     else
  795.         {
  796.         theUserEvent = UserEventList;                /* Get the first one */
  797.         while ((*theUserEvent)->Next != NIL)        /* Get the next one */
  798.             {
  799.             theUserEvent = (*theUserEvent)->Next;
  800.             }
  801.         (*theUserEvent)->Next = NewUserEvent;        /* Tack on to the end */
  802.         }
  803.     }
  804. }
  805.  
  806. /* ======================================================= */
  807.  
  808. /* Routine: SetNameForPopup */
  809. /* Purpose: Set the title for a popup control */
  810.  
  811. void SetNameForPopup(ControlHandle theControl)
  812. Handle    theHandle;                                    /* The resource handle */
  813. ResType    theType;                                    /* Returned type */
  814. short    theID;                                        /* Returned ID */
  815. short    theMenuID;                                    /* Menu ID */
  816.  
  817.  
  818. theMenuID = GetCtlMax(theControl);                    /* Get the menu ID */
  819. theHandle = Get1Resource('MENU', theMenuID);        /* See if the resource is out there */
  820. if (theHandle != nil)                                /* See if we got the menu */
  821.     GetResInfo(theHandle,&theID,&theType,sTemp);    /* Get the title */
  822. else                                                /* Else no menu here */
  823.     sTemp[0] = 0;                                    /* Get the title */
  824. SetCTitle(theControl,sTemp);                        /* Set the title */
  825. }
  826.  
  827. /* ======================================================= */
  828.  
  829. /* Routine: Make_A_List */
  830. /* Purpose: This is a routine used to make a new list */
  831.  
  832. void Make_A_List(ListHandle *theList,Rect *theListRect,WindowPtr theWindow,short theStringResourceID,
  833.     short theSize,short theFont,Style theStyle,Boolean InDialog)
  834. {
  835. Point    cSize;                                        /* Use to point to proper row */
  836. Handle    theHandle;                                    /* Temp Handle */
  837. Rect    dataBounds;
  838.  
  839.  
  840. TextSize(theSize);                                    /* Set text size */
  841. TextFont(theFont);                                    /* Set text font */
  842. TextFace(theStyle);                                    /* Set text style */
  843.  
  844. tempRect = *theListRect;
  845. tempRect.right = tempRect.right - 15;                /* Go inside the scroll bar area */
  846. SetRect(&dataBounds, 0, 0, 1, 0);                    /* Make the empty list */
  847. cSize.h = theListRect->right - 15 - theListRect->left;/* Get the width of the list */
  848. cSize.v = 0;                                        /* Set the HEIGHT of each list element, based on font selected */
  849.  
  850. *theList = LNew(&tempRect, &dataBounds, cSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE);/* Create the list */
  851. (**theList)->selFlags = lOnlyOne + lNoNilHilite;    /* Set for only one active item at a time */
  852. LDoDraw(FALSE,*theList);                            /* Do not Draw this list structure */
  853.  
  854. theHandle = Get1Resource('STR#',theStringResourceID);/* See if any strings */
  855. if (theHandle != NIL)
  856.     {
  857.     cSize.h = 0;                                    /* Point to the correct column, starts at zero */
  858.     cSize.v = -1;                                    /* Point to the correct row, starts at zero */
  859.     do
  860.         {
  861.         GetIndString(sTemp, theStringResourceID, cSize.v + 2);/* Get the new string */
  862.         if (sTemp[0] > 0)
  863.             Add_List_String(sTemp, *theList, &cSize);/* Add in the new string */
  864.         }
  865.     while (sTemp[0] != 0);                            /* Add all the strings in this resource */
  866.     }
  867.  
  868. LDoDraw(TRUE,*theList);                                /* Draw this list structure */
  869. cSize.h = 0;                                        /* All elements are in column 0e */
  870. cSize.v = 0;                                         /* Select the first list element */
  871. LSetSelect(TRUE, cSize,*theList);
  872.  
  873. if (InDialog)
  874.     TextFont(systemFont);                            /* Back to the system font */
  875. else
  876.     TextFont(applFont);                                /* Back to the application font */
  877. TextSize(12);                                        /* Back to the application size */
  878. TextFace(0);                                        /* Set text style */
  879. }
  880.  
  881. /* ======================================================= */
  882.  
  883. void Play_The_Sound(short ResID)
  884. {
  885. Handle        ResHandle;                                /* The sound resource handle */
  886. short        SndResourceID;                            /* Sound resource ID */
  887. Str255        SndName;                                /* Sound name*/
  888. ResType        theType;                                /* Resource type */
  889. OSErr        MyErr;                                    /* Error flag */
  890.  
  891.  
  892. ResHandle = Get1Resource('snd ', ResID);            /* See if the resource is out there */
  893. if (ResHandle != NIL)                                /* Only do if we got the sound */
  894.     {
  895.     GetResInfo(ResHandle,&SndResourceID,&theType,SndName);
  896.     MyErr = SndPlay(NIL,ResHandle,FALSE);
  897.     ReleaseResource(ResHandle);
  898.     }
  899. }
  900.  
  901. /* ======================================================= */
  902.  
  903. /* Routine: Add_List_String */
  904. /* Purpose: This is a routine used to add strings to an existing list */
  905.  
  906. void Add_List_String(Str255 theString,ListHandle theList,Point *cSize) 
  907. {
  908. short    theRow;                                        /* The Row that we are adding */
  909.  
  910.  
  911. if (theList != NIL)  
  912.     {
  913.     cSize->h = 0;                                    /* Point to the correct column */
  914.     theRow = LAddRow(1, 32000, theList);            /* Add another row at the end of the list */
  915.     cSize->v = theRow;                                /* Point to the row just added */
  916.     LSetCell(&theString[1], theString[0], *cSize,theList);/* Place string in row just created */
  917.     }
  918. }
  919.  
  920. /* ======================================================= */
  921.  
  922. /* Routine: Get_TE_String */
  923. /* Purpose: This is a routine used to get a string from a TE area, limited to 250 characters */
  924.  
  925. void Get_TE_String(TEHandle theTEArea,Str255 *theString)
  926. short Index;                                        /* Use to loop thru the characters */
  927. short TitleLength;                                    /* Number of characters to do */
  928. CharsHandle theCharsHandle;                            /* Used to get global edit text */
  929. Ptr theStringPtr;                                    /* Pointer to the string, byte level */
  930. Ptr theTECharPtr;                                    /* Pointer to the string, byte level */
  931.  
  932.  
  933. theCharsHandle = TEGetText(theTEArea);                /* Get the character handle */
  934. HLock ( ( Handle ) theCharsHandle );                /* Lock it for safety */
  935. theTECharPtr = (Ptr)*theCharsHandle;                /* Get string Ptr */
  936. TitleLength = (*theTEArea)->teLength;                /* Get the number of characters */
  937. *theString[0] = 0;                                    /* Start with an empty string */
  938. if (TitleLength > 0) 
  939.     {
  940.     theStringPtr = (Ptr)((long)theString + (long)1);/* Start of the string data */
  941.     if (TitleLength > 250) 
  942.         TitleLength = 250;
  943.     for (Index = 0; Index < TitleLength; Index++)
  944.         *theStringPtr++ = (char)(*theTECharPtr++);
  945.     *theString[0] = TitleLength;
  946.     }
  947. }
  948.  
  949. /* ======================================================= */
  950.  
  951. /* Routine: Make_TE_Area */
  952. /* Purpose: This is a routine used to create a TE area */
  953.  
  954. void Make_TE_Area(TEHandle *theTEArea,Rect *Position,short theFontSize,
  955.     short theFont,short DefaultStringID)
  956. {
  957. FontInfo    ThisFontInfo;                            /* Use to get the font data */
  958.  
  959.  
  960. TextSize(theFontSize);                                /* Set the size */
  961. TextFont(theFont);                                    /* Set the font */
  962. GetFontInfo(&ThisFontInfo);                            /* Get Ascent height for positioning */
  963.  
  964. tempRect = *Position;                                /* Get the rect */
  965. FrameRect(&tempRect);                                /* Frame this TE area */
  966. InsetRect(&tempRect, 3, 3);                            /* Indent for TE inside of box */
  967. *theTEArea = TENew(&tempRect, &tempRect);            /* Create the TE area */
  968. if (theInput != NIL)                                /* See if there is already a TE area */
  969.     TEDeactivate(theInput);                            /* Yes, so turn it off */
  970.  
  971. theInput = *theTEArea;                                /* Activate the TE area */
  972. GetIndString(sTemp, DefaultStringID, 1);            /* Get the default string */
  973. TESetText(&sTemp[1], sTemp[0], theInput);            /* Place default text in the TE area */
  974. TEActivate(theInput);                                /* Make the TE area active */
  975.  
  976. TextSize(12);                                        /* Set the size */
  977. TextFont(applFont);                                    /* Set the font */
  978. }
  979.  
  980. /* ======================================================= */
  981.  
  982. /* Routine: Plot_Sicn */
  983. /* Purpose: This is a routine used to plot an Sicn, small 16x16 icon */
  984.  
  985. void Plot_Sicn(short theSicnID,Rect *Position)
  986. typedef struct SmallIconRec{
  987.     long    theIcon[16];
  988. }*SmallIconPtr,**SmallIconHand;
  989.  
  990. SmallIconHand    SmallIcon;                            /* Handle to the SICN resource */
  991. BitMap            theBitMap;                            /* Bitmap for plotting */
  992. Rect            sourceRect, DestRect;                /* Rects for plotting */
  993. GrafPtr            thePort;                            /* Port to draw on to */
  994.  
  995.  
  996. SmallIcon = (SmallIconHand)GetResource('SICN', theSicnID);/* Get the resource */
  997. if (SmallIcon != NIL)                                /* Do if there is a resource */
  998.     {
  999.     SetRect(&sourceRect, 0, 0, 16, 16);                /* Sicns are 16 x 16 */
  1000.     DestRect = *Position;                            /* Destination */
  1001.     theBitMap.baseAddr = (Ptr)&(*SmallIcon)->theIcon;/* Base address of the bitmap */
  1002.     theBitMap.rowBytes = 2;                            /* 2*8 = 16 */
  1003.     theBitMap.bounds = sourceRect;                    /* Source rect size */
  1004.     GetPort(&thePort);                                /* Get the current port */
  1005.     CopyBits(&theBitMap, &thePort->portBits, &sourceRect, &DestRect, srcCopy, NIL);/* Plot it */
  1006.     }
  1007. }
  1008.  
  1009. /* ======================================================= */
  1010.  
  1011. /* Routine: HandleWScrollBar */
  1012. /* Purpose: This is a routine used to handle a scrollbar */
  1013.  
  1014. void HandleWScrollBar (Point myPt,short code,short Increment,short LIncrement,ControlHandle theControl)
  1015. {
  1016. short    theValue;                                    /* Value of the scrollbar */
  1017. long    MaxTick;                                    /* Timer used for repeat scrolling */
  1018. Boolean    FirstTime;                                    /* Flag to start scrolling */
  1019. short    Start,Stop;
  1020.  
  1021.  
  1022. Start = GetCtlMin(theControl);
  1023. Stop = GetCtlMax(theControl);
  1024.  
  1025. FirstTime = TRUE;                                    /* Do the scroll the first time also */
  1026. while (StillDown() || FirstTime)                    /* Do the scroll as long as the button is down */
  1027.     {                                                /* Timer used for repeat scrolling */
  1028.     FirstTime = FALSE;                                /* Do the scroll the first time only unless auto */
  1029.     HiliteControl(theControl, code);                /* Darken the arrow */
  1030.     theValue = GetCtlValue(theControl);                /* Get current state */
  1031.  
  1032.     if (code == inUpButton)                            /* See if in the up/left arrow */
  1033.         {
  1034.         theValue = theValue - Increment;            /* Subtract the single decrement */
  1035.         if (theValue < Start)                        /* Check for boundary conditions */
  1036.             theValue = Start;                        /* Bump at the start value */
  1037.         }
  1038.  
  1039.     if (code == inDownButton)                        /* See if in the down/right arrow */
  1040.         {
  1041.         theValue = theValue + Increment;            /* Add the single increment */
  1042.         if (theValue > Stop)                         /* Check for boundary conditions */
  1043.             theValue = Stop;                        /* Bump at the stop value */
  1044.         }
  1045.  
  1046.     if (code == inPageUp)                            /* See if in the up/left grey area */
  1047.         {
  1048.         theValue = theValue - LIncrement;            /* Subtract the page increment */
  1049.         if (theValue < Start)                         /* Check for boundary conditions */
  1050.             theValue = Start;                        /* Bump at the Start value */
  1051.         }
  1052.  
  1053.     if (code == inPageDown)                            /* See if in the down/right grey area */
  1054.         {
  1055.         theValue = theValue + LIncrement;            /* Add the page increment */
  1056.         if (theValue > Stop)                        /* Check for boundary conditions */
  1057.             theValue = Stop;                        /* Bump at the Stop value */
  1058.         }
  1059.  
  1060.     if (code == inThumb)                            /* See if in the drag box area */
  1061.         {
  1062.         code = TrackControl(theControl, myPt, NIL);    /* Let the OS drag it around */
  1063.         theValue = GetCtlValue(theControl);            /* Get current state */
  1064.         }
  1065.  
  1066.     SetCtlValue(theControl, theValue);                /* Set new state */
  1067.  
  1068.     MaxTick = TickCount() + 9;                        /* Time delay for auto-scroll */
  1069.     do                                                /* Start of delay routine */
  1070.         {}
  1071.     while ((Button()) && (TickCount() < MaxTick));    /* Exit when time up or mouse button up */
  1072.     HiliteControl(theControl, 0);                    /* Lighten the arrow */
  1073.     }                                                /* End for StillDown */
  1074. }
  1075.  
  1076. /* ======================================================= */
  1077.  
  1078. /* Routine: mySelectDlgFilter */
  1079. /* Purpose: Filter routine for Select Volume routine */
  1080.  
  1081. static pascal short mySelectDlgFilter (short item,DialogPtr theDialog,Ptr myDataPtr)
  1082. {
  1083. short            theItem;
  1084. short            theWidth;
  1085. short            theNameWidth;
  1086. short            DType;
  1087. Handle            DItem;
  1088. ControlHandle    CItem;
  1089. Str255            sTemp;
  1090. Str255            theName;
  1091. Str255            LastChar;
  1092. Point            cSize;
  1093. Rect            dataBounds;
  1094. Boolean            NamesAreSame;
  1095.  
  1096.  
  1097. theItem = item;
  1098.  
  1099. if (theItem == sfHookNullEvent)
  1100.     {
  1101.     NamesAreSame = PStrCmp((StringPtr)&Last_Name,(StringPtr)&gFiles->Files.theStdFileReply.sfFile.name);
  1102.     if ((Last_vRefNum != gFiles->Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != gFiles->Files.theStdFileReply.sfFile.parID) || (!NamesAreSame))
  1103.         theItem = sfItemFileListUser;
  1104.     }
  1105. else
  1106.     theItem = theItem;
  1107.  
  1108. if (theItem == sfItemFileListUser)
  1109.     {
  1110.     if ((Last_vRefNum != gFiles->Files.theStdFileReply.sfFile.vRefNum) || (Last_parID != gFiles->Files.theStdFileReply.sfFile.parID) || (Last_Name != gFiles->Files.theStdFileReply.sfFile.name))
  1111.         {
  1112.         Last_vRefNum = gFiles->Files.theStdFileReply.sfFile.vRefNum;
  1113.         Last_parID = gFiles->Files.theStdFileReply.sfFile.parID;
  1114.         PStrCopy((Str255 *)gFiles->Files.theStdFileReply.sfFile.name,&Last_Name);
  1115.         GetDItem(theDialog, 10, &DType, &DItem, &tempRect);
  1116.         theWidth = tempRect.right - tempRect.left - 10;
  1117.         PStrCopy((Str255 *)"\pSelect '",&sTemp );
  1118.         theWidth = theWidth - StringWidth(sTemp);
  1119.         PStrCopy((Str255 *)gFiles->Files.theStdFileReply.sfFile.name,&theName);
  1120.         theNameWidth = StringWidth(theName);
  1121.         if (theNameWidth > theWidth)
  1122.             {
  1123.             LastChar[0] = 1;
  1124.             LastChar[1] = theName[theName[0]];
  1125.             PStrCopy(&theName,&sTemp); 
  1126.             PStrCat((Str255 *)"\p...",&sTemp);
  1127.             PStrCat(&LastChar,&sTemp); 
  1128.             while (StringWidth(sTemp) > (theWidth - 5))
  1129.                 {
  1130.                 theName[0] = theName[0] - 1;
  1131.                 PStrCopy(&theName,&sTemp); 
  1132.                 PStrCat((Str255 *)"\p...",&sTemp);
  1133.                 PStrCat(&LastChar,&sTemp); 
  1134.                 }
  1135.             PStrCat((Str255 *)"\p...",&theName);
  1136.             PStrCat(&LastChar,&theName); 
  1137.             }
  1138.  
  1139.         PStrCopy((Str255 *)"\pSelect '", &sTemp );
  1140.         PStrCat(&theName,&sTemp); 
  1141.         PStrCat((Str255 *)"\p'",&sTemp);
  1142.         CItem = (ControlHandle)DItem;                /* Change dialog handle to control handle */
  1143.         SetCTitle(CItem, sTemp);
  1144.         if (gFiles->Files.theStdFileReply.sfIsFolder || gFiles->Files.theStdFileReply.sfIsVolume)
  1145.             HiliteControl(CItem, 0);
  1146.         else
  1147.             HiliteControl(CItem,255);
  1148.         }
  1149.     }
  1150. else if (theItem == 10)
  1151.     theItem = sfItemOpenButton;
  1152.  
  1153. return(theItem);
  1154. }
  1155.  
  1156. /* ======================================================= */
  1157.  
  1158. /* Routine: mySelectCustomFileFilter */
  1159. /* Purpose: Filter file routine for Select Volume routine */
  1160.  
  1161. static pascal Boolean mySelectCustomFileFilter (CInfoPBPtr pb,Ptr myDataPtr)
  1162. {
  1163. Boolean        HideTheItem;
  1164. HFileInfo    *FileRecPtr;
  1165.  
  1166.  
  1167. HideTheItem = true;
  1168. FileRecPtr = (HFileInfo *)pb;
  1169. if ((FileRecPtr->ioFlAttrib & 0x0010) != 0)            /* Doing Folder */
  1170.     HideTheItem = false;
  1171.  
  1172. return(HideTheItem);
  1173. }
  1174.  
  1175. /* ======================================================= */
  1176.  
  1177. /* Routine: Init */
  1178. /* Purpose: Init */
  1179.  
  1180. void CmmFiles::Init()
  1181. {
  1182. }
  1183.  
  1184. /* ======================================================= */
  1185.  
  1186. /* Routine: Close_The_Input_File */
  1187. /* Purpose: Close The Input File */
  1188.  
  1189. void CmmFiles::Close_The_Input_File()
  1190. {
  1191. OSErr        ErrorCode;
  1192.  
  1193.  
  1194. ErrorCode = FSClose(this->Files.inputRefNum);                /* Invalidate the refnum */
  1195. this->Files.inputRefNum = 0;                                /* Close the file */
  1196. }
  1197.  
  1198. /* ======================================================= */
  1199.  
  1200. /* Routine: Close_The_Output_File */
  1201. /* Purpose: Close the output file */
  1202.  
  1203. void CmmFiles::Close_The_Output_File()
  1204. {
  1205. OSErr        ErrorCode;
  1206.  
  1207.  
  1208. ErrorCode = FSClose(this->Files.outputRefNum);            /* Invalidate the refnum */
  1209. this->Files.outputRefNum = 0;                                /* Close the file */
  1210. }
  1211.  
  1212. /* ======================================================= */
  1213.  
  1214. /* Routine: Open_The_File */
  1215. /* Purpose: Open The File */
  1216.  
  1217. void CmmFiles::Open_The_File()
  1218. {
  1219. }
  1220.  
  1221. /* ======================================================= */
  1222.  
  1223. /* Routine: Select_Volume */
  1224. /* Purpose: Select Volume */
  1225.  
  1226. void CmmFiles::Select_Volume()
  1227. {
  1228. }
  1229.  
  1230. /* ======================================================= */
  1231.  
  1232. /* Routine: Save_The_File */
  1233. /* Purpose: Save The File */
  1234.  
  1235. void CmmFiles::Save_The_File()
  1236. {
  1237. }
  1238.  
  1239. /* ======================================================= */
  1240. /* ======================================================= */
  1241.  
  1242. /* Routine: Do_The_Select_Volume */
  1243. /* Purpose: This is a routine used to select a user selected folder or volume */
  1244. /* Return TRUE for opened the file OK, else return FALSE */
  1245.  
  1246. Boolean CmmFiles::Do_The_Select_Volume(FSSpec *theFile)        /* Select a volume */
  1247. {
  1248. short    Screen_Width;                                /* Size of the current screen */
  1249. short    Screen_Height;                                /* Size of the current screen */
  1250. Point    Where;                                        /* Used for placing the SF dialog */
  1251. Boolean    OpenedOK;                                    /* Flag to return */
  1252.  
  1253.  
  1254. Screen_Width = qd.screenBits.bounds.right - qd.screenBits.bounds.left;/* Width of this screen */
  1255. Screen_Height = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  1256.  
  1257. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1258. Where.v = (Screen_Height / 4) - (104 / 2);
  1259. if (Where.v < 60)
  1260.     Where.v = 60;
  1261. InitCursor();
  1262. this->Files.typeList[0] = 'GRC ';
  1263. Last_vRefNum = -2;
  1264. Last_parID = -2;
  1265. CustomGetFile((FileFilterYDProcPtr)mySelectCustomFileFilter,0,this->Files.typeList,&this->Files.theStdFileReply,
  1266.     512,Where,(DlgHookYDProcPtr)mySelectDlgFilter, nil, nil, nil, nil);
  1267.  
  1268. OpenedOK = false;                                    /* Init to did not open the file */
  1269. if (this->Files.theStdFileReply.sfGood)                    /* Only do if the user did not cancel */
  1270.     {
  1271.     *theFile = this->Files.theStdFileReply.sfFile;        /* Save the FSSpec */
  1272.     BlockMove((Ptr)&this->Files.theStdFileReply.sfFile.name,&this->Files.inputFileName,
  1273.         this->Files.theStdFileReply.sfFile.name[0]+1);
  1274.     OpenedOK = true;                                /* We selected a folder */
  1275.     }
  1276. else
  1277.     this->Files.inputFileName[0] = 0;                        /* No name for a folder */
  1278.  
  1279. return(OpenedOK);
  1280. }
  1281.  
  1282. /* ======================================================= */
  1283.  
  1284. /* Routine: Do_The_Open_File */
  1285. /* Purpose: This is a routine used to open a user selected file */
  1286. /* Return TRUE for opened the file OK, else return FALSE */
  1287.  
  1288. Boolean CmmFiles::Do_The_Open_File (short NumberOfTypes,short *theVolRefNum,ProcPtr fileFilter,
  1289.     ProcPtr dlgHook)
  1290. {
  1291. short    Screen_Width;                                /* Size of the current screen */
  1292. short    Screen_Height;                                /* Size of the current screen */
  1293. Point    Where;                                        /* Used for placing the SF dialog */
  1294. Boolean    OpenedOK;                                    /* Flag to return */
  1295. OSErr    ErrorCode;
  1296. SFReply    Reply;                                        /* Temp record for making SFGetFile call */
  1297.  
  1298.  
  1299. Screen_Width = qd.screenBits.bounds.right - qd.screenBits.bounds.left;/* Width of this screen */
  1300. Screen_Height = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  1301.  
  1302. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1303. Where.v = (Screen_Height / 4) - (104 / 2);
  1304. if (Where.v < 60)
  1305.     Where.v = 60;
  1306. InitCursor();
  1307. SFGetFile(Where,(StringPtr)"/pNot used",(FileFilterProcPtr)fileFilter,NumberOfTypes,
  1308.     this->Files.typeList,(DlgHookProcPtr)dlgHook,&Reply);
  1309.  
  1310. *theVolRefNum = 0;
  1311. this->Files.Reply = Reply;
  1312. this->Files.inputRefNum = 0;                        /* We did not open */
  1313.  
  1314. OpenedOK = false;                                    /* Init to did not open the file */
  1315. if (Reply.good)                                        /* Only do if the user did not cancel */
  1316.     {
  1317.     BlockMove((Ptr)&Reply.fName,&this->Files.inputFileName,Reply.fName[0]+1);
  1318.  
  1319.     ErrorCode = SetVol(nil,Reply.vRefNum);            /* Set to this volume for later opens */
  1320.     *theVolRefNum = Reply.vRefNum;
  1321.     OpenedOK = true;                                /* Flag that we are open OK */
  1322.     }
  1323. else
  1324.     this->Files.inputFileName[0] = 0;                /* No name for a file */
  1325.  
  1326. return(OpenedOK);
  1327. }
  1328.  
  1329. /* ======================================================= */
  1330.  
  1331. /* Routine: Do_The_Save_File */
  1332. /* Purpose: This is a routine used to save a user selected file */
  1333. /* Return TRUE for opened the file OK, else return FALSE */
  1334.  
  1335. Boolean CmmFiles::Do_The_Save_File (OSType creator,OSType fileType,Str255 *Prompt,Str255 *DefaultName,
  1336.     short *theVolRefNum,short *theRefNum,ProcPtr dlgHook)
  1337. {
  1338. short    Screen_Width;                                /* Size of the current screen */
  1339. short    Screen_Height;                                /* Size of the current screen */
  1340. Point    Where;                                        /* Used for placing the SF dialog */
  1341. Boolean    OpenedOK;                                    /* Flag to return */
  1342. OSErr    ErrorCode;
  1343. SFReply    Reply;                                        /* Temp record for making SFPutFile call */
  1344.  
  1345.  
  1346. Screen_Width = qd.screenBits.bounds.right - qd.screenBits.bounds.left;/* Width of this screen */
  1347. Screen_Height = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
  1348.  
  1349. Where.h = (Screen_Width / 2) - (304 / 2);            /* Place to put this dialog */
  1350. Where.v = (Screen_Height / 4) - (104 / 2);
  1351. if (Where.v < 60)
  1352.     Where.v = 60;
  1353. InitCursor();
  1354. SFPutFile(Where,(StringPtr)Prompt,(StringPtr)DefaultName,(DlgHookProcPtr)dlgHook,&Reply);
  1355.  
  1356. BlockMove((Ptr)&Reply.fName,&this->Files.outputFileName,Reply.fName[0]+1);
  1357.  
  1358. this->Files.Reply = Reply;
  1359. *theVolRefNum = this->Files.Reply.vRefNum;
  1360. *theRefNum = 0;
  1361. this->Files.outputRefNum = 0;
  1362.  
  1363. OpenedOK = false;                                    /* Init to did not open the file */
  1364. if (Reply.good)                                        /* Only do if the user did not cancel */
  1365.     {
  1366.     ErrorCode = FSDelete((StringPtr)&Reply.fName,Reply.vRefNum);    /* Delete an older file */
  1367.     ErrorCode = Create((StringPtr)&Reply.fName,Reply.vRefNum,creator,fileType);/* Create the file */
  1368.     ErrorCode = FSOpen((StringPtr)&Reply.fName,Reply.vRefNum,&this->Files.outputRefNum);/* Try to open the file */
  1369.  
  1370.     if (ErrorCode == 0)                                /* See if we opened it cleanly */
  1371.         {
  1372.         ErrorCode = SetFPos(this->Files.outputRefNum, fsFromStart, 0);/* Start at file beginning */
  1373.         ErrorCode = SetVol(nil, *theVolRefNum);        /* Set for later saves */
  1374.         *theRefNum = this->Files.outputRefNum;
  1375.         *theVolRefNum = Reply.vRefNum;
  1376.         OpenedOK = true;                            /* We opened the file OK */
  1377.         }
  1378.     else
  1379.         {
  1380.         ErrorCode = FSClose(this->Files.outputRefNum);    /* Close it if we can, safety */
  1381.         SysBeep(20);                                /* Just beep at the user, caller can do more */
  1382.         this->Files.outputRefNum = 0;                /* Make sure the refnum is inited */
  1383.         }
  1384.     }
  1385.  
  1386. return(OpenedOK);
  1387. }
  1388.  
  1389. /* ======================================================= */
  1390.  
  1391. /* Routine: Init */
  1392. /* Purpose: Init */
  1393.  
  1394. void CmmPrinting::Init()
  1395. {
  1396. this->Printing.hPrint = nil;                            /* Init to no print record yet */
  1397. this->Printing.PrinterIsOpen = false;                    /* We are not printing yet */
  1398. }
  1399.  
  1400. /* ======================================================= */
  1401.  
  1402. /* Routine: PageSetup */
  1403. /* Purpose: Do the page setup */
  1404.  
  1405. void CmmPrinting::PageSetup()
  1406. {
  1407. Boolean    Result;                                        /* Result from Setup dialog */
  1408.  
  1409.  
  1410. PrOpen();                                            /* Open the printer driver */
  1411.  
  1412. if (PrError() == noErr)                                /* Only do if no error  */
  1413.     {
  1414.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1415.         {
  1416.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1417.         HLock((Handle)Printing.hPrint);
  1418.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1419.         }
  1420.  
  1421.     Result = PrStlDialog(Printing.hPrint);            /* Setup dialog */
  1422.     PrClose();
  1423.     }
  1424. else
  1425.     SysBeep(1);
  1426. }
  1427.  
  1428. /* ======================================================= */
  1429.  
  1430. /* Routine: PrintJobSetup */
  1431. /* Purpose: Do the job setup */
  1432.  
  1433. void CmmPrinting::PrintJobSetup()
  1434. {
  1435. Boolean    Result;                                        /* Result from Setup dialog */
  1436.  
  1437.  
  1438. PrOpen();                                            /* Open the printer driver */
  1439.  
  1440. if (PrError() == noErr)                                /* Only do if no error  */
  1441.     {
  1442.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1443.         {
  1444.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1445.         HLock((Handle)Printing.hPrint);
  1446.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1447.         }
  1448.  
  1449.     Result = PrJobDialog(Printing.hPrint);            /* Setup dialog */
  1450.     PrClose();
  1451.     }
  1452. else
  1453.     SysBeep(1);
  1454. }
  1455.  
  1456. /* ======================================================= */
  1457.  
  1458. /* Routine: OpenThePrinter */
  1459. /* Purpose: Open the printer and driver for use */
  1460.  
  1461. void CmmPrinting::OpenThePrinter(Boolean *Cancelled)
  1462. {
  1463.  
  1464.  
  1465. PrOpen();                                            /* Open the printer driver */
  1466.  
  1467. if (PrError() == noErr)                                /* Only do if no error */
  1468.     {
  1469.     Printing.PrinterIsOpen = FALSE;                    /* Whether printer is open or not */
  1470.     if (Printing.hPrint == NIL)                        /* Make a print record if there is none */
  1471.         {
  1472.         Printing.hPrint = (THPrint)NewHandle(sizeof(TPrint));
  1473.         HLock((Handle)Printing.hPrint);
  1474.         PrintDefault(Printing.hPrint);                /* Init to default values */
  1475.         }
  1476.  
  1477.     *Cancelled = PrJobDialog(Printing.hPrint);        /* Setup dialog */
  1478.     Printing.CopyCount = (*Printing.hPrint)->prJob.iCopies;    /* Get number of copies to do */
  1479.     *Cancelled = !(*Cancelled);                        /* Inverted logic */
  1480.  
  1481.     Printing.pPrPort = nil;
  1482.  
  1483.     if (*Cancelled == false)                        /* Do if they did not cancel */
  1484.         {
  1485.         Printing.PrinterIsOpen = true;                /* Whether printer is open or not */
  1486.         Printing.PageCount = 1;                        /* For adding in page number */
  1487.         Printing.LineCount = 1;                        /* For printing */
  1488.         Printing.pPrPort = PrOpenDoc(Printing.hPrint, nil, nil);/* Get printing port */
  1489.         }
  1490.     }
  1491. else
  1492.     {
  1493.     SysBeep(1);
  1494.     *Cancelled = TRUE;
  1495.     }
  1496. }
  1497.  
  1498. /* ======================================================= */
  1499.  
  1500. /* Routine: CloseThePrinter */
  1501. /* Purpose: Close the printer */
  1502.  
  1503. void CmmPrinting::CloseThePrinter()
  1504. {
  1505.  
  1506.  
  1507. if (Printing.pPrPort != nil)                        /* Do if we have a port */
  1508.     {
  1509.     PrCloseDoc(Printing.pPrPort);                    /* Clear printing port */
  1510.     Printing.pPrPort = nil;
  1511.     }
  1512.  
  1513. if (Printing.hPrint != nil)                            /* Do if we have a record */
  1514.     {
  1515.     if (((*Printing.hPrint)->prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr))
  1516.         PrPicFile(Printing.hPrint, NIL, NIL, NIL, &Printing.prStatus);/* Spool it */
  1517.     }
  1518. }
  1519.  
  1520. /* ======================================================= */
  1521.  
  1522. /* Routine: Print_The_Data */
  1523. /* Purpose: Print the data */
  1524.  
  1525. void CmmPrinting::Print_The_Data()
  1526. {
  1527. }
  1528.  
  1529. /* ======================================================= */
  1530.  
  1531. /* Routine: SetupTheItem */
  1532. /* Purpose: Setup a dialog or alert item */
  1533.  
  1534. void SetupTheItem(DialogPtr theDialog,short ItemID,Boolean SizeIt,Boolean ShowIt,
  1535.     Boolean EnableIt,Boolean SetTheMax,Rect *thePosition,long ExtraData,short StringID)
  1536. {
  1537. Rect            tempRect;                            /* Temporary rectangle */
  1538. short            DType;                                /* Type of dialog item */
  1539. Handle            DItem;                                /* Handle to the dialog item */
  1540. ControlHandle    CItem;                                /* Control handle */
  1541.  
  1542.  
  1543. GetDItem(theDialog,ItemID,&DType,&DItem,&tempRect);/* Get the item handle and size */
  1544. CItem = (ControlHandle)DItem;                        /* Change to control handle */
  1545.  
  1546. if (SizeIt)                                            /* Have to resize all CDEF connected controls */
  1547.     SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1548. *thePosition = tempRect;                            /* Pass back the zone location and size */
  1549.  
  1550. if (ExtraData != NIL)                                /* See if extra data for a CDEF */
  1551.     (*CItem)->contrlData = (Handle)ExtraData;        /* Send it */
  1552.  
  1553. if (StringID != 0)                                    /* See if a CDEF and needs the title set again*/
  1554.     {
  1555.     GetIndString(sTemp,StringID,1);                    /* Get the string */
  1556.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1557.     }
  1558.  
  1559. if (EnableIt)                                        /* See if enable or disable the zone */
  1560.     HiliteControl (CItem,0);                        /* Enable the zone */
  1561. else
  1562.     HiliteControl (CItem,255);                        /* Dim the zone */
  1563.  
  1564. if (SetTheMax)
  1565.     SetCtlMax(CItem,12345);                            /* Set the flag to the CDEF */
  1566.  
  1567. if (ShowIt)
  1568.     ShowControl(CItem);                                /* Show it to activate it */
  1569. }
  1570.  
  1571. /* ======================================================= */
  1572.  
  1573. /* Routine: CenterOnColorScreen */
  1574. /* Purpose: Center a window onto the deepest color screen */
  1575.  
  1576. void CenterOnColorScreen (WindowPtr theWindow )
  1577. {
  1578. Rect        tempRect,gdRect,temp2Rect;                /* Temporary rectangle */
  1579. GDHandle    theDevice;                                /* Graphic device */
  1580.  
  1581. if ((theWindow != NIL) && (Has.ColorQD))            /* Make sure it is safe to go ahead */
  1582.     {
  1583.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1584.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1585.  
  1586.     if (theDevice != NIL)                            /* Make sure we got a device */
  1587.         {
  1588.         gdRect = (*theDevice)->gdRect;                /* Get the device rect */
  1589.         temp2Rect = theWindow->portRect;            /* Get the window rect */
  1590.  
  1591.         tempRect.top = gdRect.top + ((gdRect.bottom-gdRect.top)/2) - ((temp2Rect.bottom-temp2Rect.top)/2);
  1592.         tempRect.left = gdRect.left + ((gdRect.right-gdRect.left)/2) - ((temp2Rect.right-temp2Rect.left)/2);
  1593.         MoveWindow(theWindow, tempRect.left, tempRect.top, TRUE);/* Move the window*/
  1594.         SetPort(theWindow);                         /* Prepare to write into our window */
  1595.         }
  1596.     }
  1597. }
  1598.  
  1599. /* ======================================================= */
  1600.  
  1601. /* Routine: GetDeepestColorScreenRect */
  1602. /* Purpose: Get the deepest color screen rect */
  1603.  
  1604. void GetDeepestColorScreenRect (Rect *DeepRect )
  1605. {
  1606. Rect        tempRect;                                /* Temporary rectangle */
  1607. GDHandle    theDevice;                                /* Graphic device */
  1608.  
  1609.  
  1610. *DeepRect = qd.screenBits.bounds;                        /* Default to the main screen */
  1611. theDevice = NIL;                                    /* Default to no device */
  1612. if (Has.ColorQD)                                    /* See if color QuickDraw is around */
  1613.     {
  1614.     SetRect(&tempRect,-32000,-32000,32000,32000);    /* Look in all directions */
  1615.     theDevice = GetMaxDevice(&tempRect);            /* Get the deepest device */
  1616.  
  1617.     if (theDevice != NIL)                            /* Make sure we got a device */
  1618.         *DeepRect = (*theDevice)->gdRect;            /* Get the device rect */
  1619.     }
  1620. }
  1621.  
  1622. /* ======================================================= */
  1623.  
  1624. void HiliteDefaultButton(DialogPtr theDialog,short theItem)
  1625. {
  1626. Rect            tempRect;
  1627. short            DType;                                /* Type of dialog item */
  1628. Handle            DItem;                                /* Handle to the dialog item */
  1629.  
  1630.  
  1631. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1632. PenSize(3, 3);                                        /* Change pen to draw thick default outline */
  1633. InsetRect(&tempRect, -4, -4);                        /* Draw outside the button by 1 pixel */
  1634. FrameRoundRect(&tempRect,16,16);                    /* Draw the outline */
  1635. PenSize(1, 1);                                         /* Restore the pen size to the default value */
  1636. }
  1637.  
  1638. /* ======================================================= */
  1639.  
  1640. void CheckKeysInDialog(DialogPtr theDialog,Boolean *valMyFilter,EventRecord *theEvent,short *itemHit)
  1641. {
  1642. short            chCode;                            /* Key entered */
  1643. char            MyCmdKey;                        /* The command key */
  1644. Boolean            CmdDown;                        /* Flag for command key used */
  1645. Rect            tempRect;                        /* Temporary rectangle */
  1646. short            DType;                            /* Type of dialog item */
  1647. Handle            DItem;                            /* Handle to the dialog item */
  1648. ControlHandle    CItem;                            /* Control handle */
  1649. long            LTemp;
  1650.  
  1651.  
  1652. if (theEvent->what == keyDown)
  1653.     {
  1654.     chCode =  (short)theEvent->message & charCodeMask;/* Get character */
  1655.     MyCmdKey = (char)chCode;                        /* Change to ASCII */
  1656.     CmdDown = ((theEvent->modifiers & cmdKey) != 0);/* Get command key state */
  1657.     if (CmdDown)                                    /* Do if command key was down */
  1658.         {
  1659.         if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
  1660.             {
  1661.             DlgCut(theDialog);
  1662.             *valMyFilter = TRUE;
  1663.             }
  1664.         else if ((MyCmdKey =='c') || (MyCmdKey == 'C')) 
  1665.             {
  1666.             DlgCopy(theDialog);
  1667.             *valMyFilter = TRUE;
  1668.             }
  1669.         else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
  1670.             {
  1671.             DlgPaste(theDialog);
  1672.             *valMyFilter = TRUE;
  1673.             }
  1674.         }
  1675.     else if ((chCode == 13) || (chCode == 3))        /* CR or Enter */
  1676.         {
  1677.         *valMyFilter = TRUE;                            /* Flag we got a hit */
  1678.         *itemHit = 1;                                /* Default for CR */
  1679.         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  1680.         if (DType == (ctrlItem + btnCtrl))            /* If a button then ... */
  1681.             {
  1682.             CItem = (ControlHandle)DItem;            /* Make it a controlhandle */
  1683.             HiliteControl(CItem, 10);                /* Hilite it */
  1684.             LTemp = TickCount() + 15;                /* Flash the button for 1/4 second */
  1685.             do
  1686.                 {}
  1687.             while (LTemp > TickCount());
  1688.             HiliteControl(CItem, 0);                /* UnHilite it */
  1689.             }
  1690.         }
  1691.     }
  1692. }
  1693.  
  1694. /* ======================================================= */
  1695.  
  1696. void SetupNormalControl(DialogPtr theDialog,short theItem,Boolean Enabled,short InitialValue)
  1697. {
  1698. Rect            tempRect;                            /* Temporary rectangle variable */
  1699. short            DType;                                /* Type of dialog item */
  1700. Handle            DItem;                                /* Handle to the dialog item */
  1701. ControlHandle    CItem;                                /* Control handle */
  1702.  
  1703.  
  1704. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1705. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1706.  
  1707. if (Enabled)                                        /* See if enable or disable the zone */
  1708.     HiliteControl (CItem,0);                        /* Enable the zone */
  1709. else
  1710.     HiliteControl (CItem,255);                        /* Dim the zone */
  1711.  
  1712. SetCtlValue(CItem,InitialValue);
  1713. }
  1714.  
  1715. /* ======================================================= */
  1716.  
  1717. static void BasicSetup(DialogPtr theDialog,short theItem,Boolean Enabled,short MessageResID,
  1718.     ControlHandle *theCItem)
  1719. {
  1720. Rect            tempRect;                            /* Temporary rectangle variable */
  1721. short            DType;                                /* Type of dialog item */
  1722. Handle            DItem;                                /* Handle to the dialog item */
  1723. ControlHandle    CItem;                                /* Control handle */
  1724. Str255            sTemp;
  1725.  
  1726.  
  1727. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1728. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1729. SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);/* Size it */
  1730.  
  1731. if (Enabled)                                        /* See if enable or disable the zone */
  1732.     HiliteControl (CItem,0);                        /* Enable the zone */
  1733. else
  1734.     HiliteControl (CItem,255);                        /* Dim the zone */
  1735.  
  1736. SetCtlValue(CItem,0);
  1737.  
  1738. if (MessageResID != 0)
  1739.     {
  1740.     GetIndString(sTemp,MessageResID,1);                /* Get the string */
  1741.     SetCTitle(CItem,sTemp);                            /* Set the string */
  1742.     }
  1743. *theCItem = CItem;
  1744. }
  1745.  
  1746. /* ======================================================= */
  1747.  
  1748. void SetupHotSpot(DialogPtr theDialog,short theItem,Boolean MakeHotSpot,long LineWidth,
  1749.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1750. {
  1751. ControlHandle    CItem;                                /* Control handle */
  1752. long            LTemp;
  1753.  
  1754.  
  1755. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1756.  
  1757. if (MakeHotSpot)
  1758.     LTemp = 0x00FF0000;                                /* Tell the CDEF that it is a HotSpot */
  1759. else
  1760.     LTemp = 0x00000000;                                /* Tell the CDEF that it is a Rectangle */
  1761.  
  1762. if (MessageResID != 0)
  1763.     LTemp = LTemp + 0x01000000;
  1764.  
  1765. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  1766. LTemp = LTemp + (0x000000FF & ShadowWidth);            /* Set the shadow width */
  1767.  
  1768. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1769.  
  1770. ShowControl(CItem);                                    /* Show it to activate it */
  1771. }
  1772.  
  1773. /* ======================================================= */
  1774.  
  1775. void SetupPlugin(DialogPtr theDialog,short theItem,Boolean Enabled,long NormalID,long HilitedID,
  1776.     short MessageResID)
  1777. {
  1778. ControlHandle    CItem;                                /* Control handle */
  1779. long            LTemp;
  1780.  
  1781.  
  1782. BasicSetup(theDialog,theItem,Enabled,MessageResID,&CItem);
  1783.  
  1784. LTemp = (HilitedID * 0x00010000) + NormalID;    
  1785. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1786.  
  1787. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1788.  
  1789. ShowControl(CItem);                                    /* Show it to activate it */
  1790. }
  1791.  
  1792. /* ======================================================= */
  1793.  
  1794. void SetupMinMaxValue(DialogPtr theDialog,short theItem,short min,short max,short value)
  1795. {
  1796. Rect            tempRect;                            /* Temporary rectangle variable */
  1797. short            DType;                                /* Type of dialog item */
  1798. Handle            DItem;                                /* Handle to the dialog item */
  1799. ControlHandle    CItem;                                /* Control handle */
  1800.  
  1801.  
  1802. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1803. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1804. SetCtlMin(CItem,min);                                /* The Min */
  1805. SetCtlMax(CItem,max);                                /* The Max */
  1806. SetCtlValue(CItem,value);                            /* The first selection */
  1807. }
  1808.  
  1809. /* ======================================================= */
  1810.  
  1811. void SetupPopupMenu(DialogPtr theDialog,short theItem,Boolean Enabled,short theMenuID,short value)
  1812. {
  1813. Rect            tempRect;                            /* Temporary rectangle variable */
  1814. short            DType;                                /* Type of dialog item */
  1815. Handle            DItem;                                /* Handle to the dialog item */
  1816. ControlHandle    CItem;                                /* Control handle */
  1817.  
  1818.  
  1819. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get the item handle */
  1820. CItem = (ControlHandle)DItem;                        /* Change dialog handle to control handle */
  1821. SizeControl(CItem,tempRect.right - tempRect.left, tempRect.bottom - tempRect.top);/* Size it to the item size */
  1822. SetCtlValue(CItem,value);                            /* The first selection */
  1823. SetCtlMax(CItem,theMenuID);                            /* The max value is the menu ID */
  1824.  
  1825. if (Enabled)                                        /* See if enable or disable the zone */
  1826.     HiliteControl (CItem,0);                        /* Enable the zone */
  1827. else
  1828.     HiliteControl (CItem,255);                        /* Dim the zone */
  1829.  
  1830. SetNameForPopup(CItem);                                /* Set the popup title */
  1831. ShowControl(CItem);                                    /* Show it to activate it */
  1832. }
  1833.  
  1834. /* ======================================================= */
  1835.  
  1836. void SetupPalette(DialogPtr theDialog,short theItem,Boolean Enabled,long NumberRows,long NumberCols,
  1837.     long PalPictureID,long HiliteMethod)
  1838. {
  1839. ControlHandle    CItem;                                /* Control handle */
  1840.  
  1841.  
  1842. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1843.  
  1844. SetCtlMax(CItem,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  1845. SetCtlValue(CItem,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  1846. (*CItem)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  1847. ShowControl(CItem);                                    /* Show it to activate it */
  1848. }
  1849.  
  1850. /* ======================================================= */
  1851.  
  1852. void SetupIconSicn(DialogPtr theDialog,short theItem,Boolean Enabled,
  1853.     long NormalID,long HilitedID)
  1854. {
  1855. ControlHandle    CItem;                                /* Control handle */
  1856. long            LTemp;
  1857.  
  1858.  
  1859. BasicSetup(theDialog,theItem,Enabled,0,&CItem);
  1860.  
  1861. LTemp = (NormalID * 0x00010000) + HilitedID;    
  1862. (*CItem)->contrlData = (Handle)LTemp;                /* Send it */
  1863.  
  1864. SetCtlMax(CItem,12345);                                /* Set the flag to the CDEF */
  1865.  
  1866. ShowControl(CItem);                                    /* Show it to activate it */
  1867. }
  1868.  
  1869. /* ======================================================= */
  1870.  
  1871. void ClearTheRadio(DialogPtr theDialog,short theItem,short *value)
  1872. {
  1873. Rect            tempRect;                            /* Temporary rectangle variable */
  1874. short            DType;                                /* Type of dialog item */
  1875. Handle            DItem;                                /* Handle to the dialog item */
  1876. ControlHandle    CItem;                                /* Control handle */
  1877.  
  1878.  
  1879. GetDItem(theDialog,theItem,&DType,&DItem,&tempRect);/* Get which item was pressed */
  1880. CItem = (ControlHandle)DItem;                        /* Change the pointer for getting to the control */
  1881. SetCtlValue(CItem,0);
  1882. *value = 0;                                            /* Set the current Radio value */
  1883. }
  1884.  
  1885. /* ======================================================= */
  1886.  
  1887. void DrawStaticTextBox(short ResID,Rect *theRect,short Justify,short theSize,
  1888.     short theFont,Style theStyle)
  1889. {
  1890. Str255        sTemp;
  1891.  
  1892.  
  1893. TextSize(theSize);                            /* Set text size */
  1894. TextFont(theFont);                            /* Set text font */
  1895. TextFace(theStyle);                            /* Set text style */
  1896. GetIndString(sTemp,ResID,1);                /* Get the string */
  1897. TextBox(&sTemp[1],sTemp[0],theRect,Justify);
  1898.  
  1899. TextFont(applFont);                            /* Back to the application font */
  1900. TextSize(12);                                /* Back to the application size */
  1901. TextFace(0);                                /* Set text style */
  1902. }
  1903.  
  1904. /* ======================================================= */
  1905.  
  1906. void DrawStaticLine(short ResID,short Left,short Top,short theSize,short theFont,Style theStyle)
  1907. {
  1908. Str255        sTemp;
  1909.  
  1910.  
  1911. TextSize(theSize);                            /* Set text size */
  1912. TextFont(theFont);                            /* Set text font */
  1913. TextFace(theStyle);                            /* Set text style */
  1914. GetIndString(sTemp,ResID,1);                /* Get the string */
  1915. MoveTo(Left,Top + theSize - 3);
  1916. DrawString(sTemp);
  1917.  
  1918. TextFont(applFont);                            /* Back to the application font */
  1919. TextSize(12);                                /* Back to the application size */
  1920. TextFace(0);                                /* Set text style */
  1921. }
  1922.  
  1923. /* ======================================================= */
  1924.  
  1925. void DrawTheTEArea(Rect *theTERect,TEHandle theTE,short theSize,short theFont,Style theStyle)
  1926. {
  1927.  
  1928.  
  1929. TextSize(theSize);                            /* Set text size */
  1930. TextFont(theFont);                            /* Set text font */
  1931. TextFace(theStyle);                            /* Set text style */
  1932. FrameRect(theTERect);                        /* Frame this TE area */
  1933. if (theTE != nil)
  1934.     TEUpdate(theTERect,theTE);                /* Update the TE area */
  1935.  
  1936. TextFont(applFont);                            /* Back to the application font */
  1937. TextSize(12);                                /* Back to the application size */
  1938. TextFace(0);                                /* Set text style */
  1939. }
  1940.  
  1941. /* ======================================================= */
  1942.  
  1943. ControlHandle MakeNormalControl(WindowPtr theWindow,short theResID,Boolean Enabled,short InitialValue)
  1944. {
  1945. ControlHandle    theCtrl;
  1946.  
  1947.  
  1948. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1949. SetCtlValue(theCtrl,InitialValue);                /* Set the value */
  1950. if (Enabled)
  1951.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1952. else
  1953.     HiliteControl(theCtrl,255);                    /* Disable the control */
  1954.  
  1955. return(theCtrl);
  1956. }
  1957.  
  1958. /* ======================================================= */
  1959.  
  1960. ControlHandle MakeHotSpot(WindowPtr theWindow,short theResID,Boolean MakeHotSpot,long LineWidth,
  1961.     long ShadowWidth,short MessageResID,Boolean Enabled)
  1962. {
  1963. ControlHandle    theCtrl;
  1964. long            LTemp;
  1965. Str255            sTemp;
  1966.  
  1967.  
  1968. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new control */
  1969. HideControl(theCtrl);                            /* Hide till we set all the parameters */
  1970.  
  1971. if (Enabled)
  1972.     HiliteControl(theCtrl,0);                    /* Enable the control */
  1973. else
  1974.     HiliteControl(theCtrl,255);                    /* Disable the control */
  1975.  
  1976. if (MakeHotSpot)
  1977.     LTemp = 0x00FF0000;                            /* Tell the CDEF that it is a HotSpot */
  1978. else
  1979.     LTemp = 0x00000000;                            /* Tell the CDEF that it is a Rectangle */
  1980.  
  1981. LTemp = LTemp + ((0x000000FF & LineWidth) * 0x00000100);    /* Set the line width */
  1982. LTemp = LTemp + (0x000000FF & ShadowWidth);        /* Set the shadow width */
  1983.  
  1984. if (MessageResID != 0)
  1985.     {
  1986.     LTemp = LTemp + 0x01000000;
  1987.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  1988.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  1989.     }
  1990.  
  1991. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  1992.  
  1993. SetCtlValue(theCtrl,0);
  1994. ShowControl(theCtrl);                            /* Show it to activate it */
  1995.  
  1996. return(theCtrl);
  1997. }
  1998.  
  1999. /* ======================================================= */
  2000.  
  2001. ControlHandle MakeIconSicn(WindowPtr theWindow,short theResID,Boolean Enabled,
  2002.     long NormalID,long HilitedID)
  2003. {
  2004. ControlHandle    theCtrl;
  2005.  
  2006.  
  2007. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2008. if (Enabled)
  2009.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2010. else
  2011.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2012. (*theCtrl)->contrlData = 
  2013.         (Handle)((NormalID * 0x00010000) + HilitedID);    /* Set the icons to be used */
  2014.  
  2015. return(theCtrl);
  2016. }
  2017.  
  2018. /* ======================================================= */
  2019.  
  2020. ControlHandle MakePlugin(WindowPtr theWindow,short theResID,Boolean Enabled,
  2021.     long NormalID,long HilitedID,short MessageResID,short InitialValue)
  2022. {
  2023. ControlHandle    theCtrl;
  2024. long            LTemp;
  2025. Str255            sTemp;
  2026.  
  2027.  
  2028. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2029. HideControl(theCtrl);
  2030. if (Enabled)
  2031.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2032. else
  2033.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2034.  
  2035. LTemp = (HilitedID * 0x00010000) + NormalID;    
  2036. (*theCtrl)->contrlData = (Handle)LTemp;            /* Send it */
  2037.  
  2038. SetCtlMax(theCtrl,12345);                        /* Set the flag to the CDEF */
  2039.  
  2040. if (MessageResID != 0)
  2041.     {
  2042.     GetIndString(sTemp,MessageResID,1);            /* Get the string */
  2043.     SetCTitle(theCtrl,sTemp);                    /* Set the string */
  2044.     }
  2045.  
  2046. SetCtlValue(theCtrl,InitialValue);
  2047. ShowControl(theCtrl);                            /* Show it to activate it */
  2048.  
  2049. return(theCtrl);
  2050. }
  2051.  
  2052. /* ======================================================= */
  2053.  
  2054. void MakeMinMaxValue(ControlHandle theControl,short min,short max,short value)
  2055. {
  2056.  
  2057. SetCtlMin(theControl,min);                                /* The Min */
  2058. SetCtlMax(theControl,max);                                /* The Max */
  2059. SetCtlValue(theControl,value);                            /* The first selection */
  2060. }
  2061.  
  2062. /* ======================================================= */
  2063.  
  2064. ControlHandle MakePopupMenu(WindowPtr theWindow,short theResID,Boolean Enabled,
  2065.     short theMenuID,short value)
  2066. {
  2067. ControlHandle    theCtrl;
  2068. long            LTemp;
  2069. Str255            sTemp;
  2070.  
  2071.  
  2072. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2073. HideControl(theCtrl);
  2074. if (Enabled)
  2075.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2076. else
  2077.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2078.  
  2079. SetCtlMax(theCtrl,theMenuID);                    /* Set the menu for the CDEF */
  2080.  
  2081. SetCtlValue(theCtrl,value);
  2082. SetNameForPopup(theCtrl);                        /* Set the popup title */
  2083. ShowControl(theCtrl);                            /* Show it to activate it */
  2084.  
  2085. return(theCtrl);
  2086. }
  2087.  
  2088. /* ======================================================= */
  2089.  
  2090. void UpdateTheList(RgnHandle theRgn,ListHandle theList,Rect *theRect,short theSize,
  2091.     short theFont,Style theStyle,Boolean InDialog)
  2092. {
  2093. Rect        tempRect;
  2094.  
  2095.  
  2096. TextSize(theSize);                            /* Set text size */
  2097. TextFont(theFont);                            /* Set text font */
  2098. TextFace(theStyle);                            /* Set text style */
  2099.  
  2100. LUpdate(theRgn,theList);                    /* Update this list */
  2101. tempRect = *theRect;                        /* Start with full size */
  2102. InsetRect(&tempRect, -1, -1);                /* Set for framing */
  2103. FrameRect(&tempRect);                        /* Frame it */
  2104.  
  2105. if (InDialog)
  2106.     TextFont(systemFont);                    /* Back to the system font */
  2107. else
  2108.     TextFont(applFont);                        /* Back to the application font */
  2109. TextSize(12);                                /* Back to the application size */
  2110. TextFace(0);                                /* Set text style */
  2111. }
  2112.  
  2113. /* ======================================================= */
  2114.  
  2115. void ClickInTheList(Point myPt,short modifiers,ListHandle theList,short theSize,
  2116.     short theFont,Style theStyle,Boolean InDialog)
  2117. {
  2118. Boolean        DoubleClick;
  2119.  
  2120.  
  2121. TextSize(theSize);                            /* Set text size */
  2122. TextFont(theFont);                            /* Set text font */
  2123. TextFace(theStyle);                            /* Set text style */
  2124.  
  2125. DoubleClick = LClick(myPt,modifiers,theList);
  2126.  
  2127. if (InDialog)
  2128.     TextFont(systemFont);                    /* Back to the system font */
  2129. else
  2130.     TextFont(applFont);                        /* Back to the application font */
  2131. TextSize(12);                                /* Back to the application size */
  2132. TextFace(0);                                /* Set text style */
  2133. }
  2134.  
  2135. /* ======================================================= */
  2136.  
  2137. ControlHandle MakePalette(WindowPtr theWindow,short theResID,Boolean Enabled,long NumberRows,
  2138.     long NumberCols,long PalPictureID,long HiliteMethod)
  2139. {
  2140. ControlHandle    theCtrl;
  2141.  
  2142.  
  2143. theCtrl = GetNewControl(theResID,theWindow);    /* Make a new button */
  2144. HideControl(theCtrl);
  2145. if (Enabled)
  2146.     HiliteControl(theCtrl,0);                    /* Enable the button */
  2147. else
  2148.     HiliteControl(theCtrl,255);                    /* Disable the button */
  2149.  
  2150. SetCtlMax(theCtrl,(NumberRows * 0x00000100) + NumberCols);    /* The max value is the (rows * 0x0100) + columns */
  2151. SetCtlValue(theCtrl,(1 * 0x0100) + 1 );                /* The current value is the (rows * 0x0100) + columns */
  2152. (*theCtrl)->contrlData = (Handle)((0xFF000000 | PalPictureID) + (HiliteMethod * 0x00010000));/* Picture ID and hilite method */
  2153.  
  2154. ShowControl(theCtrl);                            /* Show it to activate it */
  2155.  
  2156. return(theCtrl);
  2157. }
  2158.  
  2159. /* ======================================================= */
  2160.  
  2161. void Activate_TE_Area(Boolean InDialog,Point myPt,TEHandle theTE,short textSize,short textFont,Style textStyle)
  2162. {
  2163.  
  2164.  
  2165. TextSize(textSize);                            /* Set text size */
  2166. TextFont(textFont);                            /* Set text font */
  2167. TextFace(textStyle);                        /* Set text style */
  2168. if (theInput != nil)                        /* See if there is already a TE area */
  2169.     TEDeactivate(theInput);                    /* ...Yes, so turn it off */
  2170.  
  2171. theInput = theTE;
  2172. TEActivate(theInput);                        /* Turn it on */
  2173. TEClick(myPt,false,theInput);
  2174. if (InDialog)
  2175.     TextFont(systemFont);                    /* Back to the system font */
  2176. else
  2177.     TextFont(applFont);                        /* Back to the application font */
  2178. TextSize(12);
  2179. TextFace(0);
  2180. }
  2181.  
  2182. /* ======================================================= */
  2183. /* ======================================================= */
  2184.